import axios from 'axios'

const service = axios.create()

// 请求拦截器
service.interceptors.request.use(
  config => {
    config.headers.token = localStorage.getItem("token")
    return Promise.resolve(config)
  },
  (error) => {
    return Promise.reject(new Error(error))
  }
)

//响应拦截器
service.interceptors.response.use(
  (response) => {
    return Promise.resolve(response.data)
  }, 
  (error) => {
    return Promise.reject(new Error(response.data.msg))
  }
)

export default service
